//
//  ResigterAllViewController.m
//  MingJiangApp
//
//  Created by wangliang on 15/3/11.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "ResigterAllViewController.h"
#import "RegisterOneCollectionViewCell.h"
#import "RegisterTwoCollectionViewCell.h"
#import "RegisterThreeCollectionViewCell.h"
#import "RegisterFinishViewController.h"
#import "RegisterInputCodeVc.h"
@interface ResigterAllViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *phoneTf;

@property (nonatomic,strong)UICollectionView *collectView;
@property (weak, nonatomic) IBOutlet UIImageView *logoImageView;
@property(nonatomic,strong)RegisterTwoCollectionViewCell *twoCell;


@end

@implementation ResigterAllViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = Color_Back_Black;
    [self UI];
}

- (IBAction)close:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)back:(id)sender {
    
    CGPoint point = self.collectView.contentOffset;
    if (point.x == 0) {
        
        [self.navigationController popViewControllerAnimated:YES];
    }else {
        
        CGFloat offSetX = point.x - CGRectGetWidth(self.collectView.frame);
        [self.collectView setContentOffset:CGPointMake(offSetX, 0) animated:YES];
    }
}


- (void)UI {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(IOS_IPHONE_WINDOW_WIDE, IOS_IPHONE_WINDOW_HIGH);
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    CGRect frame = CGRectMake(0, 0,IOS_IPHONE_WINDOW_WIDE,IOS_IPHONE_WINDOW_HIGH);
    self.collectView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
    self.collectView.delegate = self;
    self.collectView.dataSource = self;
    self.collectView.scrollEnabled = NO;
    [self.collectView registerNib:[UINib nibWithNibName:@"RegisterOneCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"one"];
    [self.collectView registerNib:[UINib nibWithNibName:@"RegisterTwoCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"two"];
    [self.collectView registerNib:[UINib nibWithNibName:@"RegisterThreeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"three"];
    
    self.collectView.backgroundColor = Color_Back_Black;
    [self.view addSubview:self.collectView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        
        RegisterOneCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"one" forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
    }else if(indexPath.row == 1) {
        
        RegisterTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"two" forIndexPath:indexPath];
        self.twoCell = cell;
        cell.delegate = self;
        return cell;
    }else {
        
        RegisterThreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"three" forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
    }
    
}


- (void)registerViewGoToNext:(id)infoDic withObject:(id)obj {
    
//    if ([obj isKindOfClass:[RegisterOneCollectionViewCell class]]) {
//        
//        [self.collectView setContentOffset:CGPointMake(CGRectGetWidth(self.collectView.frame), 0) animated:YES];
//        [self.twoCell refreshView];
//    }else if ([obj isKindOfClass:[RegisterTwoCollectionViewCell class]]) {
//        
//        [self.collectView setContentOffset:CGPointMake(CGRectGetWidth(self.collectView.frame) * 2, 0) animated:YES];
//    }else if ([obj isKindOfClass:[RegisterThreeCollectionViewCell class]]) {
//        
//        [self.navigationController pushViewController:[[RegisterFinishViewController alloc] init] animated:YES];
//    }
}

- (void)registerViewCancel:(id)infoDic withObject:(id)obj {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)registerViewGoToBack:(id)infoDic withObject:(id)obj {
    
    if ([obj isKindOfClass:[RegisterOneCollectionViewCell class]]) {
        
        [self.navigationController popViewControllerAnimated:YES];
    }else if ([obj isKindOfClass:[RegisterTwoCollectionViewCell class]]) {
        
        [self.collectView setContentOffset:CGPointMake(0, 0) animated:YES];
        
    }else if ([obj isKindOfClass:[RegisterThreeCollectionViewCell class]]) {
        
        [self.collectView setContentOffset:CGPointMake(CGRectGetWidth(self.collectView.frame), 0) animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)getAuthcode:(UIButton *)sender {
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    if (self.phoneTf.text.length<11) {
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"请正确输入手机号"];
        return;
    }
    param[@"user_name"] = self.phoneTf.text;
    [WLHTTPRequest getAuthorCodeWithParam:param usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        if([[resultDictionary cusObjectForKey:@"status"] intValue]==1){
            NSLog(@"注册验证码:%@",resultDictionary);
            [self.navigationController pushViewController:[[RegisterInputCodeVc alloc] initWithPhone:self.phoneTf.text] animated:YES];
        }else{
            
            [[DMCAlertCenter defaultCenter] postAlertWithMessage:[resultDictionary cusObjectForKey:@"msg"]];
        }
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
    
}


@end
